package com.example.system01.controller;

import com.example.system01.entity.Devices;
import com.example.system01.entity.Suppliers;
import com.example.system01.service.DevicesService;
import com.example.system01.service.SuppliersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class apiController {
    @Autowired
    DevicesService devicesService;
    @Autowired
    SuppliersService suppliersService;
    @RequestMapping("/devicesDelete")
    public Integer devicesDelete(@RequestParam String id){
        Devices devices = new Devices();
        devices.setId(Integer.valueOf(id));
//        调用service里的删除方法
        if(devicesService.delete(devices)==1){
            return 1;
        }else {
            return 0;
        }
    }

    @RequestMapping("/suppliersDelete")
    public Integer suppliersDelete(@RequestParam String id){
        Suppliers suppliers = new Suppliers();
        suppliers.setId(Integer.valueOf(id));

//        调用service里的删除方法
        if(suppliersService.delete(suppliers)==1){
            return 1;
        }else {
            return 0;
        }
    }
    @RequestMapping("/devicesUpdateProcess")
    public Integer devicesUpdateProcess(@RequestParam String Id,@RequestParam String name,@RequestParam String price
            ,@RequestParam String quantity,@RequestParam String category,@RequestParam String supplier){
//        组装一个goods实例
        Devices devices = new Devices();
        devices.setId(Integer.valueOf(Id));
        devices.setName(name);
        devices.setPrice(Double.valueOf(price));
        devices.setQuantity(Integer.valueOf(quantity));
        devices.setCategory(category);
        devices.setSupplier(supplier);
        System.out.println(devices);

//        调用service的update方法给数据库
        if (devicesService.update(devices)==1){
            //        如果返回ok，那么就进入商品管理首页
            return 1;
        }
        else{
            return 0;
        }
    }
    @RequestMapping("/suppliersUpdateProcess")
    public Integer suppliersUpdateProcess(@RequestParam String Id,@RequestParam String suppliersname,@RequestParam String addr
            ,@RequestParam String phone){
//        组装一个goods实例
        Suppliers suppliers = new Suppliers();
        suppliers.setId(Integer.valueOf(Id));
        suppliers.setSuppliersname(suppliersname);
        suppliers.setAddr(addr);
        suppliers.setPhone(phone);
        System.out.println(suppliers);

//        调用service的add方法给数据库
        if (suppliersService.update(suppliers)==1){
            //        如果返回ok，那么就进入商品管理首页
            return 1;
        }
        else{
            return 0;
        }
    }
}
